package servlet;



import Dao.RegisterDaoImpl;
import Impl.RegisterDao;
import com.google.gson.Gson;
import model.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text:html;");
        String userName=request.getParameter("userName");
        String password=request.getParameter("password");
        RegisterDao registerDao=new RegisterDaoImpl();
        ResultVO resultVO=new ResultVO();
        PrintWriter writer=response.getWriter();
        try{
            resultVO=registerDao.register(userName,password);

        } catch (SQLException throwables) {
            writer.write("error1");
        }
        writer.write(new Gson().toJson(resultVO));

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
